package com.sctvcloud.bazhong.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.application.Constances;
import com.sctvcloud.bazhong.beans.NewsItem;
import com.sctvcloud.bazhong.ui.adapter.holder.CommonFrgHolder;
import com.sctvcloud.bazhong.ui.util.IListShowData;

import java.util.List;

/**
 * Created by Administrator on 2017/6/23 0023.
 */

public class CommonFrgAdapter<T extends IListShowData> extends BaseHolderAbsAdapter<NewsItem, CommonFrgHolder> {
    private int mTemplate;//1：首条新闻大图其他新闻小图，2：全部新闻大图
    public static final int VIEW_TYPE_SMALL = 0;
    public static final int VIEW_TYPE_LARGE = 1;
    private boolean isAct = false;

    public CommonFrgAdapter(Context context, List<NewsItem> list, int template) {
        super(context, list);
        mTemplate = template;
    }

    public void setAct(boolean isAct) {
        this.isAct = isAct;
    }


    @Override
    public CommonFrgHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        switch (viewType) {
            default:
            case VIEW_TYPE_LARGE:
                view = LayoutInflater.from(context).inflate(R.layout.item_common_frg_type_2, parent, false);
                break;
            case VIEW_TYPE_SMALL:
                view = LayoutInflater.from(context).inflate(R.layout.item_common_frg_type_1, parent, false);
                break;
        }
        CommonFrgHolder holder = new CommonFrgHolder(context, view);
        holder.setAct(isAct);
        holder.setType(viewType);
        holder.setInternalClick(this);
        return holder;
    }

    @Override
    public CommonFrgAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        super.setItemInternalClick(itemInternalClick);
        return this;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return VIEW_TYPE_LARGE;
        } else {
            if (mTemplate == Constances.COMMON_FRG_VIEW_TYPE_FIRST_LARGE) {
                return VIEW_TYPE_SMALL;
            } else {
                return VIEW_TYPE_LARGE;
            }
        }
    }
}
